package com.sxt.springcloud.sys.fallback;

import com.sxt.springcloud.sys.UserClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import com.sxt.sys.domain.User;
import com.sxt.sys.vo.UserVo;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
@Component
public class UserClientFallbackService implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        return new UserClientService() {
            @Override
            public User getOne(String tokengetPrincipal) {
                return null;
            }

            @Override
            public DataGridView loadAllUser(UserVo userVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询所有用户方法失败");
            }

            @Override
            public Map<String, Object> loadUserMaxOrderNum() {
                Map<String, Object> map = new HashMap<>();
                map.put("失败方法","服务降级，服务器忙，请稍后重试！调用查询用户最大值失败");
                return map;
            }

            @Override
            public DataGridView loadUsersByDeptId(Integer deptid) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用根据部门id查询用户方法失败");
            }

            @Override
            public Map<String, Object> changeChineseToPinyin(String username) {
                Map<String, Object> map = new HashMap<>();
                map.put("失败方法","服务降级，服务器忙，请稍后重试！调用中文改为拼音方法失败");
                return null;
            }

            @Override
            public ResultObj addUser(UserVo userVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public DataGridView loadUserById(Integer id) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用根据用户id查询用户方法失败");
            }

            @Override
            public ResultObj updateUser(UserVo userVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj deleteUser(Integer id) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj resetPwd(Integer id) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public DataGridView initRoleByUserId(Integer id) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用根据用户ID查询角色并选中已拥有的角色方法失败");
            }

            @Override
            public ResultObj saveUserRole(Integer uid, Integer[] ids) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj checkedoldpwd(String oldpwd) {
                return ResultObj.RESET_ERROR;
            }

            @Override
            public ResultObj udpatepwd(String newpwd) {
                return ResultObj.SERVER_BUSY;
            }
        };
    }
}
